{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 收益率相关数据"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import optshare"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 国债及其他债券收益率曲线"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "                    曲线名称          日期      3月      6月      1年      3年      5年  \\\n0      中债中短期票据收益率曲线(AAA)  2020-02-04  2.8939  2.8998  2.9158  3.1970  3.4503   \n1    中债商业银行普通债收益率曲线(AAA)  2020-02-04  2.7215  2.7370  2.8042  2.9979  3.3120   \n2              中债国债收益率曲线  2020-02-04  1.7475  1.7630  2.1000  2.4056  2.6399   \n3              中债国债收益率曲线  2020-02-05  1.7475  1.7667  2.0773  2.4264  2.6348   \n4      中债中短期票据收益率曲线(AAA)  2020-02-05  2.7991  2.8975  2.9118  3.1949  3.4609   \n..                   ...         ...     ...     ...     ...     ...     ...   \n760  中债商业银行普通债收益率曲线(AAA)  2021-02-03  2.9102  3.0033  3.0674  3.4304  3.6579   \n761            中债国债收益率曲线  2021-02-03  2.4151  2.4300  2.6938  2.9070  3.0547   \n762    中债中短期票据收益率曲线(AAA)  2021-02-04  3.0315  3.1149  3.2310  3.6834  3.8329   \n763  中债商业银行普通债收益率曲线(AAA)  2021-02-04  2.9677  3.0019  3.1033  3.4406  3.6682   \n764            中债国债收益率曲线  2021-02-04  2.4351  2.4772  2.7155  2.9206  3.0851   \n\n         7年     10年     30年  \n0    3.7153  3.9597     NaN  \n1    3.5849  3.8158  4.2435  \n2    2.7906  2.8551  3.4488  \n3    2.7893  2.8440  3.4460  \n4    3.7157  3.9601     NaN  \n..      ...     ...     ...  \n760  3.8061  3.9443  4.5945  \n761  3.2100  3.2112  3.7588  \n762  4.0023  4.1559     NaN  \n763  3.8164  3.9546  4.6048  \n764  3.2222  3.2347  3.7711  \n\n[765 rows x 10 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>曲线名称</th>\n      <th>日期</th>\n      <th>3月</th>\n      <th>6月</th>\n      <th>1年</th>\n      <th>3年</th>\n      <th>5年</th>\n      <th>7年</th>\n      <th>10年</th>\n      <th>30年</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>中债中短期票据收益率曲线(AAA)</td>\n      <td>2020-02-04</td>\n      <td>2.8939</td>\n      <td>2.8998</td>\n      <td>2.9158</td>\n      <td>3.1970</td>\n      <td>3.4503</td>\n      <td>3.7153</td>\n      <td>3.9597</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>中债商业银行普通债收益率曲线(AAA)</td>\n      <td>2020-02-04</td>\n      <td>2.7215</td>\n      <td>2.7370</td>\n      <td>2.8042</td>\n      <td>2.9979</td>\n      <td>3.3120</td>\n      <td>3.5849</td>\n      <td>3.8158</td>\n      <td>4.2435</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>中债国债收益率曲线</td>\n      <td>2020-02-04</td>\n      <td>1.7475</td>\n      <td>1.7630</td>\n      <td>2.1000</td>\n      <td>2.4056</td>\n      <td>2.6399</td>\n      <td>2.7906</td>\n      <td>2.8551</td>\n      <td>3.4488</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>中债国债收益率曲线</td>\n      <td>2020-02-05</td>\n      <td>1.7475</td>\n      <td>1.7667</td>\n      <td>2.0773</td>\n      <td>2.4264</td>\n      <td>2.6348</td>\n      <td>2.7893</td>\n      <td>2.8440</td>\n      <td>3.4460</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>中债中短期票据收益率曲线(AAA)</td>\n      <td>2020-02-05</td>\n      <td>2.7991</td>\n      <td>2.8975</td>\n      <td>2.9118</td>\n      <td>3.1949</td>\n      <td>3.4609</td>\n      <td>3.7157</td>\n      <td>3.9601</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>760</th>\n      <td>中债商业银行普通债收益率曲线(AAA)</td>\n      <td>2021-02-03</td>\n      <td>2.9102</td>\n      <td>3.0033</td>\n      <td>3.0674</td>\n      <td>3.4304</td>\n      <td>3.6579</td>\n      <td>3.8061</td>\n      <td>3.9443</td>\n      <td>4.5945</td>\n    </tr>\n    <tr>\n      <th>761</th>\n      <td>中债国债收益率曲线</td>\n      <td>2021-02-03</td>\n      <td>2.4151</td>\n      <td>2.4300</td>\n      <td>2.6938</td>\n      <td>2.9070</td>\n      <td>3.0547</td>\n      <td>3.2100</td>\n      <td>3.2112</td>\n      <td>3.7588</td>\n    </tr>\n    <tr>\n      <th>762</th>\n      <td>中债中短期票据收益率曲线(AAA)</td>\n      <td>2021-02-04</td>\n      <td>3.0315</td>\n      <td>3.1149</td>\n      <td>3.2310</td>\n      <td>3.6834</td>\n      <td>3.8329</td>\n      <td>4.0023</td>\n      <td>4.1559</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>763</th>\n      <td>中债商业银行普通债收益率曲线(AAA)</td>\n      <td>2021-02-04</td>\n      <td>2.9677</td>\n      <td>3.0019</td>\n      <td>3.1033</td>\n      <td>3.4406</td>\n      <td>3.6682</td>\n      <td>3.8164</td>\n      <td>3.9546</td>\n      <td>4.6048</td>\n    </tr>\n    <tr>\n      <th>764</th>\n      <td>中债国债收益率曲线</td>\n      <td>2021-02-04</td>\n      <td>2.4351</td>\n      <td>2.4772</td>\n      <td>2.7155</td>\n      <td>2.9206</td>\n      <td>3.0851</td>\n      <td>3.2222</td>\n      <td>3.2347</td>\n      <td>3.7711</td>\n    </tr>\n  </tbody>\n</table>\n<p>765 rows × 10 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_bond_yield(start_date = '20200204', end_date = '20210204')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Shibor Data"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "             日期    O/N     1W     2W     1M     3M     6M     9M     1Y\n0    2021-11-01  2.030  2.168  2.158  2.398  2.449  2.537  2.671  2.783\n1    2021-11-02  2.126  2.185  2.205  2.394  2.450  2.539  2.673  2.783\n2    2021-11-03  2.000  2.137  2.186  2.397  2.452  2.541  2.675  2.784\n3    2021-11-04  1.886  2.132  2.146  2.397  2.451  2.542  2.675  2.784\n4    2021-11-05  1.887  2.129  2.213  2.398  2.451  2.542  2.673  2.780\n..          ...    ...    ...    ...    ...    ...    ...    ...    ...\n142  2022-05-26  1.364  1.765  1.737  1.875  1.990  2.136  2.243  2.325\n143  2022-05-27  1.381  1.777  1.738  1.854  1.995  2.130  2.239  2.323\n144  2022-05-30  1.405  1.814  1.803  1.856  1.997  2.126  2.236  2.319\n145  2022-05-31  1.588  1.898  1.757  1.865  1.998  2.129  2.238  2.318\n146  2022-06-01  1.413  1.652  1.641  1.865  1.998  2.130  2.238  2.317\n\n[147 rows x 9 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>O/N</th>\n      <th>1W</th>\n      <th>2W</th>\n      <th>1M</th>\n      <th>3M</th>\n      <th>6M</th>\n      <th>9M</th>\n      <th>1Y</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2021-11-01</td>\n      <td>2.030</td>\n      <td>2.168</td>\n      <td>2.158</td>\n      <td>2.398</td>\n      <td>2.449</td>\n      <td>2.537</td>\n      <td>2.671</td>\n      <td>2.783</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2021-11-02</td>\n      <td>2.126</td>\n      <td>2.185</td>\n      <td>2.205</td>\n      <td>2.394</td>\n      <td>2.450</td>\n      <td>2.539</td>\n      <td>2.673</td>\n      <td>2.783</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2021-11-03</td>\n      <td>2.000</td>\n      <td>2.137</td>\n      <td>2.186</td>\n      <td>2.397</td>\n      <td>2.452</td>\n      <td>2.541</td>\n      <td>2.675</td>\n      <td>2.784</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2021-11-04</td>\n      <td>1.886</td>\n      <td>2.132</td>\n      <td>2.146</td>\n      <td>2.397</td>\n      <td>2.451</td>\n      <td>2.542</td>\n      <td>2.675</td>\n      <td>2.784</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2021-11-05</td>\n      <td>1.887</td>\n      <td>2.129</td>\n      <td>2.213</td>\n      <td>2.398</td>\n      <td>2.451</td>\n      <td>2.542</td>\n      <td>2.673</td>\n      <td>2.780</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>142</th>\n      <td>2022-05-26</td>\n      <td>1.364</td>\n      <td>1.765</td>\n      <td>1.737</td>\n      <td>1.875</td>\n      <td>1.990</td>\n      <td>2.136</td>\n      <td>2.243</td>\n      <td>2.325</td>\n    </tr>\n    <tr>\n      <th>143</th>\n      <td>2022-05-27</td>\n      <td>1.381</td>\n      <td>1.777</td>\n      <td>1.738</td>\n      <td>1.854</td>\n      <td>1.995</td>\n      <td>2.130</td>\n      <td>2.239</td>\n      <td>2.323</td>\n    </tr>\n    <tr>\n      <th>144</th>\n      <td>2022-05-30</td>\n      <td>1.405</td>\n      <td>1.814</td>\n      <td>1.803</td>\n      <td>1.856</td>\n      <td>1.997</td>\n      <td>2.126</td>\n      <td>2.236</td>\n      <td>2.319</td>\n    </tr>\n    <tr>\n      <th>145</th>\n      <td>2022-05-31</td>\n      <td>1.588</td>\n      <td>1.898</td>\n      <td>1.757</td>\n      <td>1.865</td>\n      <td>1.998</td>\n      <td>2.129</td>\n      <td>2.238</td>\n      <td>2.318</td>\n    </tr>\n    <tr>\n      <th>146</th>\n      <td>2022-06-01</td>\n      <td>1.413</td>\n      <td>1.652</td>\n      <td>1.641</td>\n      <td>1.865</td>\n      <td>1.998</td>\n      <td>2.130</td>\n      <td>2.238</td>\n      <td>2.317</td>\n    </tr>\n  </tbody>\n</table>\n<p>147 rows × 9 columns</p>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_shibor(start_date = '20211101', end_date = '20220601')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Lpr data"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "           日期    1Y    5Y\n0  2021-11-22  3.85  4.65\n1  2021-12-20  3.80  4.65\n2  2022-01-20  3.70  4.60\n3  2022-02-21  3.70  4.60\n4  2022-03-21  3.70  4.60\n5  2022-04-20  3.70  4.60\n6  2022-05-20  3.70  4.45",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>1Y</th>\n      <th>5Y</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2021-11-22</td>\n      <td>3.85</td>\n      <td>4.65</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2021-12-20</td>\n      <td>3.80</td>\n      <td>4.65</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2022-01-20</td>\n      <td>3.70</td>\n      <td>4.60</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2022-02-21</td>\n      <td>3.70</td>\n      <td>4.60</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2022-03-21</td>\n      <td>3.70</td>\n      <td>4.60</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>2022-04-20</td>\n      <td>3.70</td>\n      <td>4.60</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>2022-05-20</td>\n      <td>3.70</td>\n      <td>4.45</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_lpr(start_date = '20211101', end_date = '20220601')"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
